#include "appidsettingwgt.h"

#include <QBoxLayout>
#include <QLabel>
#include <QLineEdit>

AppIdSettingWgt::AppIdSettingWgt(QWidget* parent)
    : QWidget(parent)
    , m_appIdEdit(new QLineEdit(this))
    , m_secretKeyEdit(new QLineEdit(this))
{
    m_appIdEdit->setMinimumWidth(200);
    m_secretKeyEdit->setMinimumWidth(200);

    m_appIdEdit->setPlaceholderText(tr("Input app id."));
    m_secretKeyEdit->setPlaceholderText(tr("Input secret key."));

    QGridLayout* contentLayout = new QGridLayout;
    contentLayout->addWidget(new QLabel(tr("App Id:"), this), 0, 0);
    contentLayout->addWidget(m_appIdEdit, 0, 1, 1, 3, Qt::AlignLeft);
    contentLayout->addWidget(new QLabel(tr("Secret Key:"), this), 1, 0);
    contentLayout->addWidget(m_secretKeyEdit, 1, 1, 1, 3, Qt::AlignLeft);

    QLabel* helpLable = new QLabel(this);
    helpLable->setText(tr("Please register your account in the link below and open the [universal translation] and [language recognition] services for free!"));
    helpLable->setWordWrap(true);

    QLabel* linkLabel = new QLabel(this);
    linkLabel->setText("<a href=\"http://api.fanyi.baidu.com/manage/developer\">Baidu Translation Open Platform</a>");
    linkLabel->setOpenExternalLinks(true);

    QVBoxLayout* mainLayout = new QVBoxLayout(this);
    mainLayout->addLayout(contentLayout);
    mainLayout->addWidget(helpLable);
    mainLayout->addWidget(linkLabel);
    mainLayout->addStretch();
}

void AppIdSettingWgt::setData(const AppIdSettingWgt::Data& data)
{
    m_appIdEdit->setText(data.appId);
    m_secretKeyEdit->setText(data.secretKey);
}

AppIdSettingWgt::Data AppIdSettingWgt::getData()
{
    Data data;
    data.appId = m_appIdEdit->text().trimmed();
    data.secretKey = m_secretKeyEdit->text().trimmed();

    return data;
}
